<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>垫款单详情列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var pageInApp = {}; // to 下一级子窗口 接口
        var pageInTab = null;
        var viewFlag = "${viewFlag}";
        $(function () {
            initTab();
            initData();
            if(viewFlag =="1"){
                $("#btnBox").hide();
            }
        });

        function initData() {
            $("#ruleNm").html('${dkRuleInfoVO.ruleNm}');
            $("#billNm").html('${dkBillInfoVO.billNm}');
            var billStsCd = ${dkBillInfoVO.billStsCd};
            var billStsCdStr = "";
            if(billStsCd != null){
                if(billStsCd=='1')
                    billStsCdStr='垫款中';
                else if(billStsCd=='0')
                    billStsCdStr='结束';
            }
            $("#billStsCd").html(billStsCdStr);
            //日期处理
            if (${dkBillInfoVO.crtTmStr!= null}) {
                $("#crtTm").html("${dkBillInfoVO.crtTmStr}");
            }
            $("#refPrjNm").html('${dkRuleInfoVO.refPrjNm}');
            var accTypCd = ${dkRuleInfoVO.accTypCd};
            var accTypCdStr = '';
            if(accTypCd != null){
                if(accTypCd == '1')
                    accTypCdStr = '承租人账户';
                else if(accTypCd == '2')
                    accTypCdStr = '我司账户';
                else if(accTypCd == '3')
                    accTypCdStr = '机构账户';
            }
            $("#accTypCd").html(accTypCdStr);
            $("#accId").html('${dkRuleInfoVO.accId}');
            var ransomExecCd = ${dkRuleInfoVO.ransomExecCd};
            var ransomExecCdStr = '';
            if(ransomExecCd!=null){
                if(ransomExecCd=='1')
                    ransomExecCdStr='标记赎回 ';
                else if(ransomExecCd='2'){
                    ransomExecCdStr='生成小贷账单 ';
                }
            }
            $("#ransomExecCd").html(ransomExecCdStr);
            var totalMaxQty = ${dkRuleInfoVO.totalMaxQty};
            if(totalMaxQty != null){
                if(totalMaxQty=='-1')
                    $("#totalMaxQty").html('无限制');
                else
                    $("#totalMaxQty").html(totalMaxQty);

            }
            var singleMaxQty = ${dkRuleInfoVO.singleMaxQty};
            if(singleMaxQty != null){
                if(singleMaxQty=='-1')
                    $("#singleMaxQty").html('无限制');
                else
                    $("#singleMaxQty").html(singleMaxQty);

            }
            $("#startOvedayDays").html('${dkRuleInfoVO.startOvedayDays}');
            $("#endOvedayDays").html('${dkRuleInfoVO.endOvedayDays}');
        }

        //设置页面数据
        function setData(data) {

            //状态
            if (data.billStsCd == 1) {
                $("#billStsCd").html("垫款中");
            } else if (data.billStsCd == 0) {
                $("#billStsCd").html("结束");
            }
            //日期处理
            if (data.crtTm) {
                var date = new Date(data.crtTm);
                var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
                $("#crtTm").html(dateStr);
            }
        };

        //初始化Tab页签
        function initTab() {
            pageInTab = $("#pageInTab").ligerTab({
                height: 'auto',
                contextmenu: false,
                minIframeHeight: GET_minIframeHeight(),
                onBeforeSelectTabItem: function (tabid) {
                   /* if (tabid != "tabA") {

                    }*/
                },

            });
            $.extend(true, pageInApp, {
                pageInTab: pageInTab
            });
        };

    </script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <form>
        <div tabid="tabA" title="垫款规则信息" lselected="true">
            <div class="fieldset1 tabel_col clearFix">
                <div class="caption">
                    <span class="title">垫款规则信息</span>
                </div>

                <div class="fieldBox col_33">
                    <div class="label">规则名称</div>
                    <div class="field">
                        <span name="ruleNm" id="ruleNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">垫款单</div>
                    <div class="field">
                        <span name="billNm" id="billNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">状态</div>
                    <div class="field">
                        <span name="billStsCd" id="billStsCd">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">生成时间</div>
                    <div class="field">
                        <span name="crtTm" id="crtTm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">再融资项目</div>
                    <div class="field">
                        <span name="refPrjNm" id="refPrjNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">收款账户</div>
                    <div class="field">
                        <span name="accTypCd" id="accTypCd">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">账户信息</div>
                    <div class="field">
                        <span name="accId" id="accId">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">赎回执行</div>
                    <div class="field">
                        <span name="ransomExecCd" id="ransomExecCd">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">最高垫款次数（累计）</div>
                    <div class="field">
                        <span name="totalMaxQty" id="totalMaxQty">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">最高垫款次数（单资产）</div>
                    <div class="field">
                        <span name="singleMaxQty" id="singleMaxQty">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">垫款类型</div>
                    <div class="field">
                        <span name="dkStyleCd" id="dkStyleCd">&nbsp;
                            <c:if test="${dkRuleInfoVO.dkStyleCd eq '0'}">暗垫</c:if>
                            <c:if test="${dkRuleInfoVO.dkStyleCd eq '1'}">明垫</c:if>
                        </span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">是否资管业务</div>
                    <div class="field">
                        <span name="isAssBiz" id="isAssBiz">
                            <c:if test="${dkRuleInfoVO.isAssBiz eq '0'}">否</c:if>
                            <c:if test="${dkRuleInfoVO.isAssBiz eq '1'}">是</c:if>
                        </span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">起租日最小时间</div>
                    <div class="field">
                        <span name="lsDtStart" id="lsDtStart">
                            ${dkRuleInfoVO.lsDtStart}
                        </span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">起租日最大时间</div>
                    <div class="field">
                        <span name="lsDtEnd" id="lsDtEnd">
                            ${dkRuleInfoVO.lsDtEnd}
                        </span>
                    </div>
                </div>
            </div>

            <div class="fieldset1 tabel_col clearFix">
                <div class="caption">
                    <span class="title">逾期天数垫款目标</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">起垫逾期天数（含）</div>
                    <div class="field">
                        <span name="startOvedayDays" id="startOvedayDays">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">最高逾期天数（含）</div>
                    <div class="field">
                        <span name="endOvedayDays" id="endOvedayDays">&nbsp;</span>
                    </div>
                </div>

            </div>

            <div class="fieldset1 tabel_col clearFix">
                <div class="caption">
                    <span class="title">符合条件支付表信息</span>
                </div>
                <div id="ligergrid" class="sq-grid"></div>

            </div>

            <div class="fieldset1 tabel_col clearFix" id="note">
                <div class="fieldBox col_100">
                    <div class="field" style="color:red">
                        <span  >合计：</span>
                        <span name="totalA" id="totalA"> 0.00</span>
                        <span name="totalB" id="totalB"> 0.00</span>
                    </div>
                </div>

                <div class="fieldBox col_100">
                    <div class="field" style="color:red">
                        <span>注意：因资管罚息数据为资方进行计算，所以执行垫付后请立即联系资方在当天完成垫付核销</span>
                    </div>
                </div>
            </div>
            <div class="btnsBox" style="display: flex; justify-content: center;" id="btnBox">
                <span id="execBtn" class="sq-button sq-button-hasicon l-dialog-btn-ok"><i class="sqBtnIco_10"></i>执行垫款</span>
            </div>
        </div>
        </form>

    </div>
</div>
</body>
<script>
    var grid = null;
    $(function(){
        var _url = '<%=path%>/dk/dkbilldtl/initMingDianPaySchList.do?dkCountMin=0&dkCountMax=${dkRuleInfoVO.totalMaxQty}&overdueDayMin=${dkRuleInfoVO.startOvedayDays}&overdueDayMax=${dkRuleInfoVO.endOvedayDays}&fundRasInsId=${dkRuleInfoVO.thdOrgId}&lsDtStart=${dkRuleInfoVO.lsDtStart}&lsDtEnd=${dkRuleInfoVO.lsDtEnd}';
        if(viewFlag == "1"){
            $("#note").hide();
            _url = '<%=path%>/dk/dkbilldtl/initViewMingDianPaySchList.do?dkCountMin=0&dkCountMax=${dkRuleInfoVO.totalMaxQty}&overdueDayMin=${dkRuleInfoVO.startOvedayDays}&overdueDayMax=${dkRuleInfoVO.endOvedayDays}&billId=${billId}&fundRasInsId=${dkRuleInfoVO.thdOrgId}';
            grid = $("#ligergrid").ligerGrid({
                url: _url,
                method : 'get',
                columns: [
                    { display: '支付表编号',name:'paySchNo', align:'left', width: 200},
                    { display: '承租人名称', name:'cstNm',align:'left', width: 200},
                    { display: '起租日',  name:'lsDt',align:'left', width: 200},
                    { display: '逾期天数', width: 80,name: 'overdueDay'},
                    { display:'逾期金额',name : 'overdueAmount', align:'left', width: 100,
                        render: function (rowdata, rowindex, value){
                            return FormatMoney(rowdata.overdueAmount/100)
                        }
                    },
                    { display: '罚息', width: 80,name: 'billStsCd',
                        render: function (rowdata, rowindex, value){
                            return FormatMoney(rowdata.penaltyAmount/100)
                        }
                    },

                ],
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:'300',
                heightDiff:-2,
                checkbox:false,
                fixedCellHeight: false,
                rownumbers:true,
                onSelectRow:calTotal,
                onUnSelectRow:calTotal,
//			onAfterShowData: getFlowIds,
            });
        }else{
            grid = $("#ligergrid").ligerGrid({
                url: _url,
                method : 'get',
                columns: [
                    { display: '支付表编号',name:'paySchNo', align:'left', width: 200},
                    { display: '承租人名称', name:'cstNm',align:'left', width: 200},
                    { display: '起租日',  name:'lsDt',align:'left', width: 200},
                    { display: '逾期天数', width: 80,name: 'overdueDay'},
                    { display:'逾期金额',name : 'arAmt', align:'left', width: 100,
                        render: function (rowdata, rowindex, value){
                            return FormatMoney(rowdata.arAmt/100)
                        }
                    },
                    { display: '罚息', width: 80,name: 'billStsCd',
                        render: function (rowdata, rowindex, value){
                            return FormatMoney(rowdata.penaltyAmount/100)
                        }
                    },

                ],
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:'300',
                heightDiff:-2,
                checkbox:true,
                fixedCellHeight: false,
                rownumbers:true,
                onSelectRow:calTotal,
                onUnSelectRow:calTotal,
//			onAfterShowData: getFlowIds,
            });
        }



        $("#execBtn").click(function(){
            var billId = "${dkBillInfoVO.id}";
            var ruleId = "${dkRuleInfoVO.id}"
            var paySchIds = [];
            var selectedRows = grid.getSelectedRows();
            if(selectedRows && selectedRows.length >0){
                var waiting = $.ligerDialog.waitting('正在执行中,请稍候...');
                for(var row of selectedRows){
                    paySchIds.push(row.id);
                }
                var url = '<%=path%>/dk/dkbilldtl/doMingDian.do';
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {paySchIds:JSON.stringify(paySchIds),billId:billId,ruleId:ruleId},
                    url: url,
                    success:function(data){
                        if(data.success==0){
                            $.ligerDialog.error(data.info)
                            waiting.close();
                        }else{
                            $.ligerDialog.success(data.info,"提示",function(){
                                Remove_navTab();
                            })
                        }
                        // var success = data.success;
                        // if(success == "1" && StringUtils.isEmpty(applyId)){
                        //     $.ligerDialog.success('保存完毕',"提示",function(){
                        //         var callback = GET_W2Wcallback();
                        //         callback();
                        //         Remove_navTab();
                        //     })
                        // }else if(success == "1"){
                        //     $.ligerDialog.success('保存完毕');
                        // }else{
                        //     $.ligerDialog.error(data.info)
                        // }
                    }
                });
            }else{
                $.ligerDialog.error("请选择支付表！");
            }
        })
    })
    function calTotal(){
        var A = 0,B=0;
        var selectedRows = grid.getSelectedRows();
        for(var s of selectedRows){
            A += s.arAmt;
            B += s.penaltyAmount;
        }
        A = A/100;
        B = B/100;
        $("#totalA").html(FormatMoney(A));
        $("#totalB").html(FormatMoney(B));
    }
</script>
</html>
